package com.javaee.xiangyang.controller.Android;

import com.javaee.xiangyang.common.ServiceResultEnum;
import com.javaee.xiangyang.dto.GoodsDetails;
import com.javaee.xiangyang.entity.Classify;
import com.javaee.xiangyang.entity.Goods;
import com.javaee.xiangyang.service.GoodsService;
import com.javaee.xiangyang.vo.ServerResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/Goods")
public class GoodsController {

    @Resource
    GoodsService goodsService;

//    /**
//     * 获取所有分类
//     */
//    @GetMapping("/GetAllGoodsClassify")
//    public ServerResponse<List<Classify>> getAllGoodsClassify(){
//        List<Classify> allClassify = goodsService.findAllClassify();
//        if (allClassify != null){
//            return ServerResponse.creatServerResponseBySuccess(allClassify);
//        }
//        return ServerResponse.creatServerResponseByFail("分类数据为空,请联系系统管理员!");
//    }

    /**
     * 根据分类编号获取分类商品下所有商品的具体信息(包括分类信息)
     */
    @GetMapping("/GetClassifyById")
    public ServerResponse<Classify> GetClassifyById(Classify classify){
        Classify classifyById = goodsService.findClassifyById(classify);
        if (classifyById != null){
            return ServerResponse.creatServerResponseBySuccess(classifyById);
        }
        return ServerResponse.creatServerResponseByFail("该分类不存在!");
    }

//    /**
//     * 根据分类编号获取分类商品下所有商品的具体信息(不包括分类信息)
//     */
//    @GetMapping("/GetAllGoodsByClassifyId")
//    public ServerResponse<List<Goods>> getAllGoodsByClassifyId(Classify classify){
//        List<Goods> allGoodsByClassifyId = goodsService.findAllGoodsByClassifyId(classify);
//        if (allGoodsByClassifyId != null){
//            return ServerResponse.creatServerResponseBySuccess(allGoodsByClassifyId);
//        }
//        return ServerResponse.creatServerResponseByFail("返回数据为空!");
//    }


    /**
     * 获取所有分类以及分类下所有数据
     * 分类
     *      商品
     */
    @GetMapping("/GetAllGoodsAndClassify")
    public ServerResponse<List<Classify>> getAllGoodsAndClassify(){
        List<Classify> allClassifyAndGoods = goodsService.findAllClassifyAndGoods();
        if (allClassifyAndGoods != null){
            return ServerResponse.creatServerResponseBySuccess(allClassifyAndGoods);
        }
        return ServerResponse.creatServerResponseByFail("分类数据为空,请联系系统管理员!");
    }

    /**
     * 获取当前商品具体信息(包括评论)
     */
    @GetMapping("/GetGoodsDetails")
    public ServerResponse<GoodsDetails> getGoodsDetails(Goods goods){
        GoodsDetails goodsDetails = goodsService.findGoodsDetails(goods);
        if (goodsDetails != null){
            return ServerResponse.creatServerResponseBySuccess(goodsDetails);
        }
        return ServerResponse.creatServerResponseByFail(ServiceResultEnum.GOODS_NOT_EXIST.getResult());
    }

}
